package com.cneport.das.server.util.receive;

import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.jms.listener.DefaultMessageListenerContainer;
import org.springframework.jms.support.destination.DynamicDestinationResolver;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @author GavinZhang
 * @version 1.0
 * @desc： 消息接收者配置工具类
 * @company 东方物通科技有限（北京）公司
 * @date 2021/9/9 17:23
 */
public class ReceiverConfHelp {
    static public DefaultMessageListenerContainer getContainer(CachingConnectionFactory jmsQueueConnectionFactory, DynamicDestinationResolver jmsDestinationResolver, MqMessageListener jmsListener, ThreadPoolTaskExecutor jmsListenerTaskExecutor, int concurrentConsumers, int maxConcurrentConsumers, String destinationName) {
        DefaultMessageListenerContainer jmsCt = new DefaultMessageListenerContainer();
        jmsCt.setConnectionFactory(jmsQueueConnectionFactory);
        jmsCt.setDestinationResolver(jmsDestinationResolver);
        jmsCt.setMessageListener(jmsListener);
        jmsCt.setCacheLevelName("CACHE_CONSUMER");
        jmsCt.setTaskExecutor(jmsListenerTaskExecutor);
        jmsCt.setConcurrentConsumers(concurrentConsumers);
        jmsCt.setMaxConcurrentConsumers(maxConcurrentConsumers);
        jmsCt.setDestinationName(destinationName);
        return jmsCt;
    }
}
